﻿using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;

namespace SoldiHive.Infrustructure.Extensions
{
	public static class EnumExtensions
	{
		public static string GetDescription(this Enum me)
		{
			Type type = me.GetType();

			MemberInfo[] memberInfo = type.GetMember(me.ToString());

			if (memberInfo != null && memberInfo.Length > 0)
			{
				object[] attributes = memberInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
				if (attributes != null && attributes.Length > 0)
				{
					return ((DescriptionAttribute)attributes.First()).Description;
				}
			}

			return me.ToString();
		}
	}
}
